package com.fsm.system.controller;

import com.fsm.common.log.config.LogData;
import com.fsm.common.log.entity.TSystemOperationLog;
import com.fsm.common.log.entity.dto.OperationEnum;
import com.fsm.common.log.entity.dto.SystemTypeEnum;
import com.fsm.common.tools.Result.Result;
import com.fsm.system.service.TSystemOperationLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *  操作日志接口。
 *
 * @author 翻山鸣
 * @since 2024/04/20
 */
@RestController
@Tag(name = "操作日志接口")
@RequestMapping("/tSystemOperationLog")
public class TSystemOperationLogController {

    @Autowired
    private TSystemOperationLogService oTSystemOperationLogService;

    /**
     * 分页查询操作日志
     *
     * @param tSystemOperationLog
     * @return 分页对象
     */
    @LogData(value = "分页查询操作日志",operation = OperationEnum.SELECT,systemTypeEnum = SystemTypeEnum.BACKEND)

    @PostMapping("pageTSystemOperationLog")
    @Operation(summary="分页查询操作日志",description="分页查询操作日志")
    public Result pageTSystemOperationLog(@RequestBody TSystemOperationLog tSystemOperationLog) throws Exception{
        return oTSystemOperationLogService.pageTSystemOperationLog(tSystemOperationLog);
    }

    /**
     * 导出操作日志
     *
     * @param response
     * @return
     */
    @LogData(value = "导出操作日志",operation = OperationEnum.EXPORT,systemTypeEnum = SystemTypeEnum.BACKEND)

    @PostMapping("uploadTSystemOperationLogData")
    @Operation(summary="导出操作日志",description="导出操作日志")
    public Result uploadTSystemOperationLogData(@RequestBody TSystemOperationLog tSystemOperationLog, HttpServletResponse response) throws Exception{
        return oTSystemOperationLogService.uploadTSystemOperationLogData(tSystemOperationLog,response);
    }

    /**
     * 清除操作日志
     * 放开@Scheduled注解后，每年底除操作日志，保留近一个月数据
     *
     * @param
     * @return 分页对象
     */
//    @Scheduled(cron = "59 59 23 31 12 ?")
    public void cleanTSystemOperationLog() throws Exception{
        oTSystemOperationLogService.cleanTSystemOperationLog();
    }

}
